/*
 * 
 *
 * 
 * [40] 最小的k个数,
 * 输出数组按从小到大排列
 */

// @lc code=start
class Solution
{
public:
    vector<int> getLeastNumbers_Solution(vector<int> input, int k)
    {
        priority_queue<int> heap;
        for (auto x : input)
        {
            // 这两行已经搞定了，heap里面存放最小的k个数，后面只是按从小到大打印
            heap.push(x);
            if (heap.size() > k)
                heap.pop();
        }

        vector<int> res;
        while (heap.size())
            res.push_back(heap.top()), heap.pop();

        reverse(res.begin(), res.end());
        return res;
    }
};
// @lc code=end
